<template>
  <div class="dateView">
    <el-card>
      <div id="main1"></div>
    </el-card>
    <el-card>
      <div id="main2"></div>
    </el-card>
  </div>
</template>

<script>
import { dataview } from "@/api/work";
export default {
  name: "DataView",
  created() {
    dataview().then((res) => {
      //console.log(res.data.data);
      if (res.data.status == 200) {
        let { legend, xAxis, series } = res.data.data;
        this.draw(legend, xAxis, series);
      }
    });
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    var myChart = this.$echarts.init(document.getElementById("main1"));
    // 绘制图表
    myChart.setOption({
      title: {
        text: "大佬进阶班",
      },
      tooltip: {},
      xAxis: {
        data: ["1班", "2班", "3班", "4班", "5班", "6班"],
      },
      yAxis: {},
      series: [
        {
          name: "人数",
          type: "bar",
          data: [5, 20, 36, 10, 10, 20],
        },
      ],
    });
  },
  methods: {
    draw(legend, xAxis, series) {
      var myChart1 = this.$echarts.init(document.getElementById("main2"));
      let option = {
        title: {
          text: "会话量",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: legend,
        },
        xAxis: {
          type: "category",
          data: xAxis,
        },
        yAxis: {
          type: "value",
        },
        series: series,
      };
      myChart1.setOption(option);
    },
  },
};
</script>

<style lang="less" scoped>
.dateView {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .el-card {
    width: 50%;
    #main1,
    #main2 {
      height: 500px;
    }
  }
}
</style>